package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.ApAuthorService;
import com.heima.model.article.pojo.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author by jojo
 * @Date 2022/2/27
 * @Description
 */
@Api(value = "app作者管理API",tags = "app作者管理API")
@RestController
@RequestMapping("/api/v1/author")
public class ApAuthorController {
    @Autowired
    private ApAuthorService apAuthorService;

    @ApiOperation(value = "查询作者",notes = "根据appUserId查询关联作者信息")
    @GetMapping("/findByUserId/{userId}")
    public ResponseResult findByUserId(@PathVariable("userId") Integer userId){
        LambdaQueryWrapper<ApAuthor> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ApAuthor::getUserId,userId);
        ApAuthor apAuthor = apAuthorService.getOne(wrapper);
        return ResponseResult.okResult(apAuthor);
    }

    @ApiOperation(value = "保存作者",notes = "保存作者信息")
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ApAuthor apAuthor){
        apAuthorService.save(apAuthor);
        return ResponseResult.okResult();
    }
}
